(function() {


})()

let swiper = document.querySelector('.swiper');
let itemContainer = document.querySelector('#item-container')
let leftBtn = document.querySelector('.left')
let rightBtn = document.querySelector('.right')
let items = document.querySelectorAll('.item')

let firstItemClone = items[0].cloneNode(true)
let lastItemClone = items[items.length - 1].cloneNode(true)

itemContainer.append(firstItemClone)
itemContainer.prepend(lastItemClone)

//获取swiper的容器宽度
const swiperWidth = parseFloat(getComputedStyle(swiper).width)
    //当前轮播图的索引
let rawindex = 0;
let index = 0;
let rawCount = items.length
let count = itemContainer.childElementCount

itemContainer.style.width = count * swiperWidth + "px"

function init() {
    itemContainer.style.transform = `translateX(${-swiperWidth*(index+1)}px)`
}
init()

function next() {
    if (index)
        itemContainer.style.transform = `translateX(${-swiperWidth*++index}px)`

}

function prev() {
    index = index == 0 ? count : index
    itemContainer.style.transform = `translateX(${-swiperWidth*--index}px)`
}

function moveTo(i) {
    i = i >= count ? count - 1 : i;
    i = i <= 0 ? 0 : i;
    index = i;
    itemContainer.style.transform = `translateX(${-swiperWidth*i}px)`
}